﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using Utils;
using Maticsoft.DBUtility;

public partial class AjaxPage_manage_ajax_dialog_teamdetail : BasePage
{
    // Fields
    protected int backsendcount = 0;
    protected int buycount = 0;
    protected int buycount1 = 0;
    protected decimal cardpay = 0M;
    protected bool couponno = false;
    protected decimal creditpay = 0M;
    protected decimal creditpay1 = 0M;
    protected int mailcount = 0;
    protected decimal onlinepay = 0M;
    protected decimal onlinepay1 = 0M;
    protected int paycount = 0;
    protected int paycount1 = 0;
    protected int sendcount = 0;
    protected bool showbutton = false;
    protected bool showdingyue = false;
    protected bool showsmsautosmscoupon = false;
    protected bool showsmscoupon = false;
    protected int smscount = 0;
    protected TeamState state = TeamState.none;
    protected NameValueCollection team = new NameValueCollection();
    protected Maticsoft.Model.Team teamm = null;

    // Methods
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!((base.IsSupper || base.IsPartner) || base.IsManage))
        {
            base.Response.Clear();
            base.Response.Write("没有权限访问");
            base.Response.End();
        }
        else
        {
            if (base.IsPartner)
            {
                this.showbutton = false;
            }
            else
            {
                this.showbutton = true;
            }
            int @int = Helper.GetInt(base.Request["id"], 0);
            this.teamm = new Maticsoft.BLL.Team().GetModel(@int);
            this.team = Helper.GetObjectProtery(this.teamm);
            this.buycount = Helper.GetInt(DbHelperSQL.Query("select sum(Quantity) from [order] where Team_id=" + this.teamm.Id + " and State='pay'").Tables[0].Rows[0][0], 0) + Helper.GetInt(DbHelperSQL.Query("select sum(Num) from [Order],orderdetail where [Order].Id=orderdetail.Order_id and  Teamid=" + this.teamm.Id + " and State='pay'").Tables[0].Rows[0][0], 0);
            this.paycount = Helper.GetInt(DbHelperSQL.Query("select count(*) from [order] where Team_id=" + this.teamm.Id + " and State='pay'").Tables[0].Rows[0][0], 0) + Helper.GetInt(DbHelperSQL.Query("select Count([Order].Id) from [Order],orderdetail where [Order].Id=orderdetail.Order_id and  Teamid=" + this.teamm.Id + " and State='pay'").Tables[0].Rows[0][0], 0);
            this.onlinepay = Helper.GetDecimal(DbHelperSQL.Query("select sum(Money) from [order] where Team_id=" + this.teamm.Id + " and State='pay'").Tables[0].Rows[0][0], 0M) + Helper.GetDecimal(DbHelperSQL.Query("select isnull(sum(Num*Teamprice),0) from [Order],orderdetail where [Order].Id=orderdetail.Order_id and  Teamid=" + this.teamm.Id + " and State='pay'  and [Order].Service!='credit'").Tables[0].Rows[0][0], 0M);
            this.creditpay = Helper.GetDecimal(DbHelperSQL.Query("select sum(Credit) from [order] where Team_id=" + this.teamm.Id + " and State='pay'").Tables[0].Rows[0][0], 0M) + Helper.GetDecimal(DbHelperSQL.Query("select isnull(sum(Num*Teamprice),0) from [Order],orderdetail where [Order].Id=orderdetail.Order_id and  Teamid=" + this.teamm.Id + " and State='pay'  and [Order].Service='credit'").Tables[0].Rows[0][0], 0M);
            this.sendcount = Helper.GetInt(DbHelperSQL.Query("select count(*) from coupon where Team_id=" + this.teamm.Id + " and Sms>0").Tables[0].Rows[0][0], 0);
            this.cardpay = Helper.GetDecimal(DbHelperSQL.Query("select sum(Card) from [order] where Team_id=" + this.teamm.Id + " and State='pay'").Tables[0].Rows[0][0], 0M);
            string str = " 1=1";
            if (this.teamm.City_id != 0)
            {
                str = " city_id=" + this.teamm.City_id;
            }
            this.mailcount = Helper.GetInt(DbHelperSQL.Query("select count(*) from mailer where " + str).Tables[0].Rows[0][0], 0);
            this.smscount = Helper.GetInt(DbHelperSQL.Query("select count(*) from Smssubscribe where Enable='Y' and " + str).Tables[0].Rows[0][0], 0);
            this.state = base.GetState(this.teamm);
            if (this.teamm.Delivery == "coupon")
            {
                if (((this.state == TeamState.successbuy) || (this.state == TeamState.successnobuy)) || (this.state == TeamState.successtimeover))
                {
                    this.couponno = true;
                    this.showsmscoupon = true;
                    if (this.buycount > this.sendcount)
                    {
                        this.showsmsautosmscoupon = true;
                        this.backsendcount = this.buycount - this.sendcount;
                    }
                }
                else
                {
                    this.couponno = false;
                }
            }
            if (((this.state == TeamState.none) || (this.state == TeamState.begin)) || (this.state == TeamState.successbuy))
            {
                this.showdingyue = true;
            }
        }
    }

}